﻿namespace Blaze.Framework.MonoEventListeners
{
    using UnityEngine;

    public class App : MonoBehaviour
    {
        public event BooleanEventHandler OnApplicationFocusEvent;
        public event BooleanEventHandler OnApplicationPauseEvent;
        public event EventHandler OnApplicationQuitEvent;

        public static App Get(GameObject obj)
        {
            return obj.GetOrAddComponent<App>();
        }

        private void OnApplicationFocus(bool hasFocus)
        {
            if (OnApplicationFocusEvent != null)
                OnApplicationFocusEvent(gameObject, hasFocus);
        }

        private void OnApplicationPause(bool isPause)
        {
            if (OnApplicationPauseEvent != null)
                OnApplicationPauseEvent(gameObject, isPause);
        }

        private void OnApplicationQuit()
        {
            if (OnApplicationQuitEvent != null)
                OnApplicationQuitEvent(gameObject);
        }
    }
}